package com.mrzhou.core.tool.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

    public class DateUtil {

        public static final String FORMAT_DATA = "yyyy-MM-dd"; // 日期格式
        public static final String FORMAT_TIME = "HH:mm:ss"; // 时间格式
        public static final String FORMAT_DATE_TIME = FORMAT_DATA + " " + FORMAT_TIME; // 日期时间格式

        public static Date now() {
            return new Date();
        }

        public static  Date parse(String str) {
            try {
                SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATE_TIME);
                return sdf.parse(str);
            } catch (Exception e) {
                e.printStackTrace();
                return now();
            }
        }

        public static  Date parse(String str, String format) {
            try {
                SimpleDateFormat sdf = new SimpleDateFormat(format);
                return sdf.parse(str);
            } catch (Exception e) {
                return now();
            }
        }

    }
